package com.source.hotelbath.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Parcelable;
import android.support.v4.content.LocalBroadcastManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.source.hotelbath.R;
import com.source.hotelbath.base.CustomerAdapter;
import com.source.hotelbath.model.GoodsListBean;
import com.source.hotelbath.model.PostBean;
import com.source.hotelbath.net.CustomerRequestConstants;
import com.source.hotelbath.utils.TintDrawable;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by ZhouMeng on 2017/9/29.
 */

public class CreateOrderAdapter extends CustomerAdapter {


    private Context mContext;

    private List<PostBean> orderGoodsList=new ArrayList<>();
    private String totle;
    private int sums;

    public CreateOrderAdapter(Context context, List<PostBean> orderGoodsList, String totle, int sums) {
        this.mContext=context;
        this.orderGoodsList=orderGoodsList;
        this.totle=totle;
        this.sums=sums;
    }

    @Override
    public int getCount() {
        if (orderGoodsList.size()>0){
            return orderGoodsList.size()+1;
        }else {
            return 0;
        }

    }

    @Override
    public Object getItem(int position) {
        return getItem(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

            ViewHolder holder;
            if (null == convertView) {
                holder = new ViewHolder();
                convertView = LayoutInflater.from(mContext).inflate(R.layout.item_create_order, null);
                holder.tv_goods_name = (TextView) convertView.findViewById(R.id.tv_goods_name);
                holder.tv_price = (TextView) convertView.findViewById(R.id.tv_price);
                holder.tv_num = (TextView) convertView.findViewById(R.id.tv_num);
                holder.tv_totle= (TextView) convertView.findViewById(R.id.tv_totle);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }

          if (orderGoodsList.size()==position){
              holder.tv_goods_name.setText("合计");
              holder.tv_price.setText("-");
              holder.tv_num.setText(sums+"");
              holder.tv_totle.setText(totle);
          }else {
              PostBean postBean= orderGoodsList.get(position);
              holder.tv_goods_name.setText(postBean.getGoodsName());
              holder.tv_price.setText("￥"+postBean.getUnitPrice());
              holder.tv_num.setText(postBean.getNum()+"");
              holder.tv_totle.setText(TintDrawable.mul(new BigDecimal(postBean.getUnitPrice()),postBean.getNum()+"")+"");
          }


        return convertView;
    }

    class ViewHolder {

        TextView tv_goods_name;
        TextView tv_price;
        TextView tv_num;
        TextView tv_totle;

    }
}
